import json
import requests

url = 'https://movie.douban.com/j/search_subjects'

params = {
    "type": "movie",
    "tag": "热门",
    "page_limit": 50,
    "page_start": 0,
}

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
}

res = requests.get(url, params=params, headers=headers)

with open('douban.txt','w',encoding='utf-8') as f:
    f.write(res.text)

with open('douban.txt', 'r', encoding='utf-8') as f:
    # json.loads() 方法用于将str转化为对象
    print(json.loads(f.read()))

res.close()  # 关掉,否则之后不能请求了
